package cn.est.controller;
import cn.est.pojo.SysUsers;
import cn.est.constants.Constants;
import cn.est.dto.Page;
import cn.est.dto.Result;
import cn.est.service.SysUsersService;
import cn.est.utils.EmptyUtils;
import cn.est.utils.ResultUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Map;

@Controller
@RequestMapping("/client/sysUsers")
public class SysUsersController {

    @Resource
    private SysUsersService sysUsersService;

    @RequestMapping("/search")
    @ResponseBody
    public Page<SysUsers> searchSysUsers(@RequestParam Map<String,Object> param) {
        Page<SysUsers> sysUsersPage = null;
        try {
            Integer pageNo= EmptyUtils.isEmpty(param.get("pageNo"))? Page.DEFAULT_PAGE_NO:Integer.parseInt((String) param.get("pageNo"));
            Integer pageSize= EmptyUtils.isEmpty(param.get("pageSize"))? Page.DEFAULT_PAGE_SIZE:Integer.parseInt((String) param.get("pageSize"));
            sysUsersPage  = sysUsersService.querySysUsersPageByMap(param, pageNo, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sysUsersPage;
    }

    @RequestMapping("/saveOrUpdateSysUsers")
    @ResponseBody
    public Result saveOrUpdateSysUsers(SysUsers sysUsers){
        Integer flag=0;
        try {
            if(EmptyUtils.isEmpty(sysUsers.getId())){
                flag=sysUsersService.qdtxAddSysUsers(sysUsers);
            }else{
                flag=sysUsersService.qdtxModifySysUsers(sysUsers);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag>=1?ResultUtils.returnSuccess():ResultUtils.returnFail();
    }

    @RequestMapping("/getSysUsersById")
    @ResponseBody
    public Result getSysUsersById(Long id){
        Result result= ResultUtils.returnSuccess();
        SysUsers sysUsers=null;
        try {
            sysUsers=sysUsersService.getSysUsersById(id);
            result.setData(sysUsers);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/batchRemoveSysUsers")
    @ResponseBody
    public Result batchRemoveSysUsers(String ids){
        Integer flag=0;
        try {
            flag=sysUsersService.qdtxBatchDeleteSysUsers(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }

    @RequestMapping("/removeSysUsersById")
    @ResponseBody
    public Result removeSysUsersById(Long id){
        Integer flag=0;
        try {
            flag=sysUsersService.qdtxDeleteSysUsersById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultUtils.returnSuccess();
    }
}
